clear
set more off
graph drop _all
set type double
import excel "\\file\UsersW$\wrr15\Home\My Documents\My Files\ANDY KIM\REVISION FOR WORLD DEVELOPMENT\DATA AND CODE\MA Data (13 July 2016).xlsx", firstrow case(lower)
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\ANDY KIM\REVISION FOR WORLD DEVELOPMENT\DATA AND CODE\Part3.smcl", replace


//CONVERTING TSTATS TO PARTICAL CORRELATION COEFFICIENTS, r
gen eff = sqrt(tstat^2/(tstat^2+df))
gen r = eff if positive == 1
replace r = -1*eff if r == .
gen varR = (1-r^2)/df
gen seR = sqrt(varR)
gen pcc = r


// RECODING VARIABLES
// The first thing we do is generate some new variables
// because some of our old study characteristics had too few
// observations
gen endog = (tsls == 1 | gmm == 1)
gen se_notols = (se_het == 1 | se_other == 1)
gen fdigdp = fditype0


*--------------------------------------------------------------------------------*
*   TABLE 6:  Predicted PCC values                                               *
*--------------------------------------------------------------------------------*

// FIXED EFFECTS
gen pubyearr = pubyear/seR 
gen datayearr = datayear/seR 
gen spann = span/seR 
gen subsett = subset/seR 
gen fdigdpp = fdigdp/seR
gen initiall = initial/seR
gen endogg = endog/seR
gen se_notolss = se_notols/seR
gen dvtype11 = dvtype1/seR 
gen dvtype22 = dvtype2/seR 
gen dvtype_otherr = dvtype_other/seR 
gen panel_nofee = panel_nofe/seR 
gen panel_fee = panel_fe/ seR 
gen tss = ts/seR   
gen cjournall = cjournal/seR 
gen notjournall = notjournal/seR 
gen conss = 1/seR
gen journalrankk = journalrank/seR
gen fetstatR = r/seR 
gen ones = 1

set obs 281

// These are the parameter values for the "preferred model"
replace pubyearr = 2010 in 281
replace datayearr = 1997.5 in 281
replace spann = 25 in 281
replace subsett = 0 in 281
replace fdigdpp = 1 in 281
replace initiall = 1 in 281
replace endogg = 1 in 281
replace se_notolss = 1 in 281
replace dvtype11 = 0 in 281
replace dvtype22 = 1 in 281
replace dvtype_otherr = 0 in 281
replace panel_nofee = 0 in 281
replace panel_fee = 1 in 281
replace tss = 0 in 281
replace cjournall = 0 in 281
replace notjournall = 0 in 281
replace journalrankk = 1 in 281
replace conss = 1 in 281
replace ones = 0 in 281

gen yfew1 = . 
gen sefew1 = . 
gen yfew2 = . 
gen sefew2 = .


// This section calculates predicted values for the two FE equations

// FIXED EFFECTS


//Calculating predicted PCC for the prefereed specification
//This regression gives equal weight to each estimate
quietly reg fetstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss ones in 1/280,  noc vce(cluster id)
 
predict yfew11 in 281, xb 
predict sefew11 in 281, stdp
replace yfew1 = yfew11 in 281
replace sefew1 = sefew11 in 281

//Calculating predicted PCC for the prefereed specification
//This regression gives equal weight to each study
quietly reg fetstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss ones [pweight = weight] in 1/280, noc vce(cluster id)

predict yfew22 in 281, xb 
predict sefew22 in 281, stdp
replace yfew2 = yfew22 in 281
replace sefew2 = sefew22 in 281

// This section calculates lower and upper bounds for a 2 sd confidence interval

gen lbfew1 = yfew1 - 2*sefew1 in 281
gen ubfew1 = yfew1 + 2*sefew1 in 281

gen lbfew2 = yfew2 - 2*sefew2 in 281
gen ubfew2 = yfew2 + 2*sefew2 in 281


// RANDOM EFFECTS

metareg r pubyear datayear span subset fdigdp initial endog ///
se_notols dvtype1 dvtype2 dvtype_other panel_nofe panel_fe ts ///
cjournal notjournal journalrank in 1/280, wsse(seR)
scalar tau2 = e(tau2)
display tau2
gen revarR= varR + tau2
gen reseR = sqrt(revarR)

replace pubyearr = pubyear/reseR 
replace datayearr = datayear/reseR 
replace spann = span/reseR 
replace subsett = subset/reseR 
replace fdigdpp = fdigdp/reseR
replace initiall = initial/reseR
replace endogg = endog/reseR
replace se_notolss = se_notols/reseR
replace dvtype11 = dvtype1/reseR 
replace dvtype22 = dvtype2/reseR 
replace dvtype_otherr = dvtype_other/reseR 
replace panel_nofee = panel_nofe/reseR 
replace panel_fee = panel_fe/ reseR 
replace tss = ts/reseR   
replace cjournall = cjournal/reseR 
replace notjournall = notjournal/reseR 
replace journalrankk = journalrank/reseR
replace conss = 1/reseR
gen retstatR = r/reseR 

// These are the parameter values for the "preferred model"
replace pubyearr = 2010 in 281
replace datayearr = 1997.5 in 281
replace spann = 25 in 281
replace subsett = 0 in 281
replace fdigdpp = 1 in 281
replace initiall = 1 in 281
replace endogg = 1 in 281
replace se_notolss = 1 in 281
replace dvtype11 = 0 in 281
replace dvtype22 = 1 in 281
replace dvtype_otherr = 0 in 281
replace panel_nofee = 0 in 281
replace panel_fee = 1 in 281
replace tss = 0 in 281
replace cjournall = 0 in 281
replace notjournall = 0 in 281
replace journalrankk = 1 in 281
replace conss = 1 in 281
gen yrew1 = . 
gen serew1 = . 
gen yrew2 = . 
gen serew2 = .


// This section calculates predicted values for the two RE equations

// RANDOM EFFECTS

//Calculating predicted PCC for the prefereed specification
//This regression gives equal weight to each estimate
quietly reg retstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss ones in 1/280, noc vce(cluster id)
 
predict yrew11 in 281, xb 
predict serew11 in 281, stdp
replace yrew1 = yrew11 in 281
replace serew1 = serew11 in 281

//Calculating predicted PCC for the prefereed specification
//This regression gives equal weight to each study
quietly reg retstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss ones [pweight = weight] in 1/280, noc  vce(cluster id)

predict yrew22 in 281, xb 
predict serew22 in 281, stdp
replace yrew2 = yrew22 in 281
replace serew2 = serew22 in 281

// This section calculates lower and upper bounds for a 2 sd confidence interval

gen lbrew1 = yrew1 - 2*serew1 in 281
gen ubrew1 = yrew1 + 2*serew1 in 281

gen lbrew2 = yrew2 - 2*serew2 in 281
gen ubrew2 = yrew2 + 2*serew2 in 281

// This section print out the results

list yfew1 lbfew1 ubfew1 in 281
list yfew2 lbfew2 ubfew2 in 281
list yrew1 lbrew1 ubrew1 in 281
list yrew2 lbrew2 ubrew2 in 281

log close

